package com.sun.mybatisplus.controller;

import com.sun.mybatisplus.bean.User;
import com.sun.mybatisplus.service.UserService;
import com.sun.mybatisplus.utils.ExcelExportUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDate;
import java.util.List;

@RestController
public class ExportExcelController {

    @Resource
    private UserService userService;

    @Autowired(required = false)
    private ExcelExportUtils excelExportUtils;

    @RequestMapping("/exportUser")
    public void exportUser(){
        List<User> list = userService.list();
        try {
            excelExportUtils.exportExcel(list,User.class,"用户信息","员工信息的sheet","用户信息表");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception{
//        String encode = URLEncoder.encode("测试","UTF-8");
//        System.out.println("============" + encode);
//        String decode = URLDecoder.decode(encode, "UTF-8");
//        System.out.println("++++++++++++++++++" + decode);
        User user = new User();
        user.setDate(LocalDate.now());
        System.out.println(user);
    }

}
